package com.hanggold.jfinal.idea.bean;

import com.hanggold.jfinal.idea.controller.LicenseController;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.beans.factory.config.InstantiationAwareBeanPostProcessor;
import org.springframework.stereotype.Component;

/**
 * @author <a href="mailto:sunmch@163.com">smc</a>
 * @date 2021-06-11 08:29
 * @since 1.0.0
 **/
@Component
public class BeanPostProcesserDemo implements InstantiationAwareBeanPostProcessor, BeanPostProcessor {
    
    @Override
    public Object postProcessBeforeInstantiation(final Class<?> beanClass, final String beanName) throws BeansException {
        if (LicenseController.class == beanClass) {
            System.out.println("执行postProcessBeforeInstantiation===");
        }
        
        return null;
    }
    
    @Override
    public boolean postProcessAfterInstantiation(final Object bean, final String beanName) throws BeansException {
        if (LicenseController.class == bean.getClass()) {
            System.out.println("执行postProcessAfterInstantiation===");
        }
        
        return true;
    }
    
    @Override
    public Object postProcessBeforeInitialization(final Object bean, final String beanName) throws BeansException {
        if (LicenseController.class == bean.getClass()) {
            System.out.println("执行postProcessBeforeInitialization===");
        }
        return bean;
    }
    
    @Override
    public Object postProcessAfterInitialization(final Object bean, final String beanName) throws BeansException {
        if (LicenseController.class == bean.getClass()) {
            System.out.println("执行postProcessAfterInitialization===");
        }
        return bean;
    }
}
